package com.google.code.jaail;

import com.google.code.jaail.networks.ChatNetwork;
import com.google.code.jaail.networks.connection.ConnectionStatus;
import com.google.code.jaail.user.MessageReceiver;

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class JaailKeeper {
    final List<ChatNetwork> registeredNetworks;

    public JaailKeeper() {
        registeredNetworks = Collections.synchronizedList(new ArrayList<ChatNetwork>());
    }

    public void connect() throws IOException {
        for (ChatNetwork network : registeredNetworks) {
            network.connect();
        }
    }

    public void addMessageReceiver(MessageReceiver messageReceiver, ChatNetwork network) {
        network.addMessageReceiver(messageReceiver);
    }

    public void addChatNetwork(ChatNetwork network) {
        registeredNetworks.add(network);
    }

    public ConnectionStatus reportConnectionStatus(ChatNetwork chatNetwork) {
        return chatNetwork.connectionStatus();
    }

    public void disconnect() throws IOException {
        for (ChatNetwork network : registeredNetworks) {
            network.disconnect();
        }
    }
}
